home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swaga_c.zip / CMDLINE.SWG / 0007_Command Position.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  2KB  |  35 lines

  1. {
  2. I have two BAsm Procedures I have written to speed up a Program which scans a
  3. comma delimited line.    My testing has shown 50,000 iterations of this
  4. Function to be approx 3 seconds faster than TP's  Var := Pos(',',String);
  5.  
  6. I am fairly new to Assembly.   This Function doES in fact work, but not as fast
  7. as I feel it should.    Can anyone see any places I have gone wrong in speed?
  8. I've avoided copying the String to the stack, by just declaring a Pointer
  9. Variable as the Function's input.  I'd like to squeeze a couple more seconds
  10. out of it if I could.   The Procedures will deal With about 6 megs of data all
  11. on comma delimited lines.
  12.  
  13. I suppose I COULD speed it up, by not declaring ANY Variable, and hard-code it
  14. to specifically use the String Variable I am currently passing to it.
  15.  }
  16.  
  17. Function Commapos(Var STRNG) : Byte; Assembler; Asm
  18.  LES DI, STRNG     { Point ES:DI to beginning of STRNG }
  19.  xor CH, CH        { Just in Case anything is in Register CH }
  20.  MOV CL, [ES:DI]   { Load String Length into CL }
  21.  MOV AH, CL        { Save len to Compute commapos later }
  22.  inC DI            { Point to First Char in String }
  23.  MOV AL, ','       { Looking For Comma }
  24.  CLD
  25. @SCANForCOMMALOOP:
  26.  SCASB             { Compare [ES:DI] to contents of AL, inc DI, Dec CL}
  27.  JE @FOUND_COMMA   { Found a Comma! }
  28.  LOOP @SCANForCOMMALOOP  { No Such Luck! }
  29.  MOV AL, 0         { Loop Fell through, no comma exists, set position to 0 }
  30.  JMP @OUTTAHERE    { JumpOut of Loop and Exit } @FOUND_COMMA:
  31.  DEC CL            { Reduce by one, since DI was advanced past the comma }
  32.  SUB AH, CL        { Subtract CL from AH to give the position }
  33.  MOV AL, AH        { Put the result into AL to return to Turbo } @OUTTAHERE:
  34. end;
  35.